PROGRAM test;

  TYPE 
    IntPtr = ^INTEGER;

  VAR 
    intVar, x, y: INTEGER;
    ptrToIntVar, iPtr: IntPtr;

  PROCEDURE Swap(VAR a: INTEGER; VAR b: INTEGER);
    VAR h: INTEGER;
  BEGIN 
    h := a;a := b;b := h;
  END;

  PROCEDURE SwapViaPointers(aPtr: IntPtr; bPtr: IntPtr);
    VAR h: INTEGER;
  BEGIN 
    h := aPtr^;aPtr^ := bPtr^;bPtr^ := h;
  END;

BEGIN 
  intVar := 10;
  ptrToIntVar := addr(intVar);
  WriteLn(ptrToIntVar^);
  ptrToIntVar^ := 12;
  WriteLn(ptrToIntVar^);

  x := 17;y := 4;
  Swap(VAR x, VAR y);
  WriteLn(x, '+', y);
  x := 1;y := 2;
  SwapViaPointers(addr(x), addr(y));
  WriteLn(x, '+', y);

  New(iPtr);
  IF iPtr = NIL THEN BEGIN 
    WriteLn('Error! Heap overflow');
    HALT;
  END ;
  WriteLn(iPtr^);
  iPtr^ := 11;
  WriteLn(iPtr^);
  Dispose(iPtr);
  iPtr := NIL;
  ReadLn();
END.